home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / XSTACK.CPP < prev    next >
C/C++ Source or Header  |  1993-03-22  |  1KB  |  29 lines

  1. #include "point.h"
  2. #include "rect.h"
  3. #include "stack.h"
  4.  
  5. main()
  6. {
  7.     cout << "\nTest class Stack\n";
  8.     Rectangle a(0,0,10,10);     // create Rectangle, a
  9.     Point A(1,2);               // create Point, A
  10.     Point B(3,4);               // create Point, B
  11.  
  12.     Object* C = A.copy();       // C is a generic pointer
  13.                                 // pointing to a copy
  14.                                 // of the Point, A
  15.  
  16.     Stack s(10);                // create polymorphic Stack, s
  17.     s.push(B);                  // push Point B onto s
  18.     s.push(a);                  // push Rectangle onto s
  19.     s.push(A);                  // push Point A onto s
  20.  
  21.     cout << s << "\n";
  22.     cout << "top compare C = " << s.top()->compare(*C) << "\n";
  23.     cout << *(s.pop()) << "\n"; // pop Point and print
  24.     cout << *(s.top()) << "\n"; // pop Rectangle and print
  25.     s.pop();                    // pop B
  26.     s.pop();                    // should get underflow error
  27. s.pop(); // should not take 4 pops, but it does
  28. }
  29.